﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:params="clr-namespace:Elysium.Parameters"
                    xmlns:primitives="clr-namespace:Elysium.Controls.Primitives">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/Elysium;component/Themes/SharedResources.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="{x:Type primitives:CommandButtonBase}" TargetType="{x:Type primitives:CommandButtonBase}">
        <Setter Property="Background" Value="{StaticResource BackgroundBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource LowlightBrush}"/>
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldThickness), Mode=OneWay}"/>
        <Setter Property="params:CommandButtons.Mask" Value="{StaticResource LowlightBrush}"/>
        <Setter Property="Foreground" Value="{StaticResource ForegroundBrush}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.ContentFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>
        <Setter Property="TextOptions.TextFormattingMode" Value="Display"/>
        <Setter Property="TextOptions.TextRenderingMode" Value="ClearType"/>
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled"/>
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.SemiBoldPadding), Mode=OneWay}"/>
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type primitives:CommandButtonBase}">
                    <Grid Background="{StaticResource TransparentBrush}"
                          TextBlock.Foreground="{TemplateBinding Foreground}"
                          TextBlock.FontFamily="{TemplateBinding FontFamily}"
                          TextBlock.FontSize="{TemplateBinding FontSize}"
                          TextBlock.FontStretch="{TemplateBinding FontStretch}"
                          TextBlock.FontStyle="{TemplateBinding FontStyle}"
                          TextBlock.FontWeight="{TemplateBinding FontWeight}"
                          TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                          TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                          RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Ellipse x:Name="PART_Decor"
                                 Grid.Row="0"
                                 Fill="{TemplateBinding Background}"
                                 Stroke="{TemplateBinding BorderBrush}"
                                 StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                                 Stretch="Fill"
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Center"/>
                        <ContentPresenter x:Name="PART_ContentHost"
                                          Grid.Row="0"
                                          Content="{TemplateBinding Content}"
                                          ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                          Margin="{TemplateBinding Padding}"
                                          RecognizesAccessKey="True"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"/>
                        <ContentPresenter x:Name="PART_HeaderHost"
                                          Grid.Row="1"
                                          Content="{TemplateBinding Header}"
                                          ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                          ContentTemplate="{TemplateBinding HeaderTemplate}"
                                          ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="Center"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Header" Value="{x:Null}">
                            <Setter TargetName="PART_HeaderHost" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource ForegroundBrush}"/>
                <Setter Property="params:CommandButtons.Mask" Value="{StaticResource ForegroundBrush}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="BorderBrush" Value="{StaticResource MiddleLightBrush}"/>
                <Setter Property="params:CommandButtons.Mask" Value="{StaticResource MiddleLightBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
                <Setter Property="params:CommandButtons.Mask" Value="{StaticResource DisabledBrush}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="CommandButtonBaseApplicationBarStyle" TargetType="{x:Type primitives:CommandButtonBase}">
        <Setter Property="Background" Value="{StaticResource TransparentBrush}"/>
        <Setter Property="BorderBrush" Value="{StaticResource ContrastBrush}"/>
        <Setter Property="BorderThickness" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.BoldThickness), Mode=OneWay}"/>
        <Setter Property="params:CommandButtons.Mask" Value="{StaticResource ContrastBrush}"/>
        <Setter Property="Foreground" Value="{StaticResource ContrastBrush}"/>
        <Setter Property="FontSize" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.ContentFontSize), Mode=OneWay}"/>
        <Setter Property="FontStretch" Value="Medium"/>
        <Setter Property="FontStyle" Value="Normal"/>
        <Setter Property="FontWeight" Value="Normal"/>      
        <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisualStyle}"/>
        <Setter Property="Padding" Value="{Binding RelativeSource={RelativeSource Self}, Path=(params:General.SemiBoldPadding), Mode=OneWay}"/>
        <!-- Temporary removed to fix bugs 1144, 1174, 1216 -->
        <!--<Setter Property="OverridesDefaultStyle" Value="True"/>-->
        <Setter Property="SnapsToDevicePixels" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type primitives:CommandButtonBase}">
                    <Grid Background="{StaticResource TransparentBrush}"
                          TextBlock.Foreground="{TemplateBinding Foreground}"
                          TextBlock.FontFamily="{TemplateBinding FontFamily}"
                          TextBlock.FontSize="{TemplateBinding FontSize}"
                          TextBlock.FontStretch="{TemplateBinding FontStretch}"
                          TextBlock.FontStyle="{TemplateBinding FontStyle}"
                          TextBlock.FontWeight="{TemplateBinding FontWeight}"
                          TextOptions.TextFormattingMode="{TemplateBinding TextOptions.TextFormattingMode}"
                          TextOptions.TextRenderingMode="{TemplateBinding TextOptions.TextRenderingMode}"
                          RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                          SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <Ellipse x:Name="PART_Decor"
                                 Grid.Row="0"
                                 Fill="{TemplateBinding Background}"
                                 Stroke="{TemplateBinding BorderBrush}"
                                 StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                                 Stretch="Fill"
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Center"/>
                        <Ellipse Grid.Row="0"
                                 Fill="{TemplateBinding params:CommandButtons.Mask}"
                                 Stroke="{StaticResource TransparentBrush}"
                                 StrokeThickness="{Binding BorderThickness, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessToDoubleConverter}}"
                                 Stretch="Fill"
                                 HorizontalAlignment="Center"
                                 VerticalAlignment="Center"
                                 Width="{Binding ElementName=PART_Decor, Path=ActualWidth, Mode=OneWay}"
                                 Height="{Binding ElementName=PART_Decor, Path=ActualHeight, Mode=OneWay}">
                            <Ellipse.OpacityMask>
                                <VisualBrush AutoLayoutContent="True"
                                             AlignmentX="Center"
                                             AlignmentY="Center"
                                             Stretch="None">
                                    <VisualBrush.Visual>
                                        <ContentPresenter x:Name="PART_ContentHost"
                                                          Content="{TemplateBinding Content}"
                                                          ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                                          ContentTemplate="{TemplateBinding ContentTemplate}"
                                                          ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                                                          Margin="{TemplateBinding Padding}"
                                                          RecognizesAccessKey="True"/>
                                    </VisualBrush.Visual>
                                </VisualBrush>
                            </Ellipse.OpacityMask>
                        </Ellipse>
                        <ContentPresenter x:Name="PART_HeaderHost"
                                          Grid.Row="1"
                                          Content="{TemplateBinding Header}"
                                          ContentStringFormat="{TemplateBinding HeaderStringFormat}"
                                          ContentTemplate="{TemplateBinding HeaderTemplate}"
                                          ContentTemplateSelector="{TemplateBinding HeaderTemplateSelector}"
                                          Margin="{TemplateBinding Padding}"
                                          HorizontalAlignment="Center"/>
                    </Grid>                    
                    <ControlTemplate.Triggers>
                        <Trigger Property="Header" Value="{x:Null}">
                            <Setter TargetName="PART_HeaderHost" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                    </ControlTemplate.Triggers>                    
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=FontSize, Mode=OneWay, Converter={StaticResource IsGreaterThanConverter}, ConverterParameter=18}">
                <Setter Property="TextOptions.TextFormattingMode" Value="Ideal"/>
            </DataTrigger>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource SemitransparentContrastBrush}"/>
                <Setter Property="BorderBrush" Value="{StaticResource ContrastBrush}"/>
                <Setter Property="params:CommandButtons.Mask" Value="{StaticResource ContrastBrush}"/>
            </Trigger>
            <Trigger Property="IsPressed" Value="True">
                <Setter Property="Background" Value="{StaticResource ContrastBrush}"/>
                <Setter Property="BorderBrush" Value="{StaticResource ContrastBrush}"/>
                <Setter Property="params:CommandButtons.Mask" Value="{StaticResource AccentBrush}"/>
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="BorderBrush" Value="{StaticResource DisabledBrush}"/>
                <Setter Property="Foreground" Value="{StaticResource DisabledBrush}"/>
                <Setter Property="params:CommandButtons.Mask" Value="{StaticResource DisabledBrush}"/>
            </Trigger>
        </Style.Triggers>        
    </Style>

</ResourceDictionary>